<?php
    require_once('root.php');
    
    $autoload = array();
    function __autoload($class_name) {
            static $autoload;
            include_once(ROOT . '/autoload.array.php' );

            if( isset( $autoload[ $class_name ] ) ) {
                    include_once($autoload[ $class_name ]);
                    return true;
            }
            return false;
    }
    spl_autoload_register(__autoload);
    $db = Database::getInstance();
    $db->query("SET NAMES 'utf8'");
    
/* SESSION */
	# Session lifetime of 3 hours
	ini_set('session.gc_maxlifetime', 10800);

	# Enable session garbage collection with a 1% chance of
	# running on each session_start()
	ini_set('session.gc_probability', 1);
	ini_set('session.gc_divisor', 100);

	# Our own session save path; it must be outside the
	# default system save path so Debian's cron job doesn't
	# try to clean it up. The web server daemon must have
	# read/write permissions to this directory.

	session_save_path(ROOT . '/sessions');
	
	session_name('reports');

	if(isset($_POST[session_name()]))
	{
		session_id($_POST[session_name()]);
	}
	else if(isset($_GET[session_name()]))
	{
		session_id($_GET[session_name()]);
	}
	
	session_start();
        
        if(!TheUser::isLoggedIn() && !TheUser::aboutToLogIn()) {
            header("Location: login.php");
        }
	
/* ------- */ 
?>
